package com.ep.commondialog;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.TypedValue;
import android.view.View;
import android.widget.Toast;

import com.ep.commondialog.dialog.AlertDialog;

public class MainActivity extends AppCompatActivity {
    private AlertDialog mAlertDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void testDialog(View view){
        mAlertDialog=new AlertDialog.Builder(this).setContentView(R.layout.dialog_test)
               // .fromBottom(false)
                .setWidthAndHeight(dpToPx(260),dpToPx(166))
                .setText(R.id.tv_title,"这是个对话框")
                .addDefaultAnimation()
                .setIcon(R.id.iv_icon,R.drawable.icon_success)
                .setOnClickListener(R.id.tv_cancle, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(MainActivity.this,"点击了取消",Toast.LENGTH_LONG).show();
                        mAlertDialog.dismiss();
                    }
                })
                .setOnClickListener(R.id.tv_confirm, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(MainActivity.this,"点击了确定",Toast.LENGTH_LONG).show();
                        mAlertDialog.dismiss();
                    }
                })
                .setCancelable(true)
                .create();
        mAlertDialog.show();
    }

    private int dpToPx(int i) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,i,getResources().getDisplayMetrics());
    }
}
